package com.android.lovely.ui.adapter

import com.android.lovely.R
import com.android.lovely.databinding.ItemOptimizationBinding
import com.android.lovely.framework.BaseAdapter
import com.kotlin.extensions.appContext
import com.kotlin.extensions.view.ViewExt.clickable

class OptimizationAdapter : BaseAdapter<Pair<Int, String>, ItemOptimizationBinding>(
    listOf(
        1 to appContext.getString(R.string.optimize_1),
        2 to appContext.getString(R.string.optimize_2),
        3 to appContext.getString(R.string.optimize_3),
        5 to appContext.getString(R.string.optimize_4),
        7 to appContext.getString(R.string.optimize_5),
        4 to appContext.getString(R.string.optimize_6),
        8 to appContext.getString(R.string.optimize_7),
        6 to appContext.getString(R.string.optimize_8),
        10 to appContext.getString(R.string.optimize_9),
    )
) {

    var currentOptimization = -1
        private set

    override fun bindViewWithHolderDetails(holder: ViewHolder, item: Pair<Int, String>?, binding: ItemOptimizationBinding, position: Int) {
        val (id, name) = item ?: return
        binding.item.text = name
        binding.item.isSelected = id == currentOptimization
        binding.item.clickable {
            currentOptimization = id
            onItemClick?.invoke(item, position)
            notifyDataSetChanged()
        }
    }
}